<template>
  <div>
    <table class="layui-table">
      <thead>
        <tr>
          <th class="title">帖子标题</th>
          <th class="text-right">收藏时间</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="(item,index) in list" :key="'col'+index">
          <td><router-link class="link" :to="{name:'detail', params: {tid:item.tid}}">{{item.title}}</router-link></td>
          <td class="text-right">{{item.created | formatDate}}</td>
        </tr>
      </tbody>
    </table>
    <Pagination v-show="list.length > 0 && total > 0" @changeCurrent="changeCurrent" :total="total" :size="limit" :current="current" :showEnd="false" :showType="'icon'"></Pagination>
  </div>
</template>

<script>
import { getCollect } from '@/api/user'
import Pagination from '@/components/modules/pagination/pagination'
export default {
  name: 'mycollection',
  components: {
    Pagination
  },
  data () {
    return {
      current: 0,
      limit: 10,
      list: [],
      total: 0
    }
  },
  mounted () {
    this.getMyCollect()
  },
  methods: {
    changeCurrent (val, limit) {
      this.current = val
      this.limit = limit
      this.getMyCollect()
    },
    async getMyCollect () {
      const res = await getCollect({ page: this.current, limit: this.limit })
      if (res.code === 200) {
        this.list = res.data
        this.total = res.total
      } else {
        this.$pop('shake', res.msg)
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.title{
  width: 70%;
}
</style>
